<?php
/**
 * Created by 王跃达.
 * User: 小马出行
 * Date: 2017/8/24
 * Time: 16:17
 */

namespace app\api\model;

use think\Db;
use think\Model;

class PersonModel extends Model
{


    public function __construct()
    {
        parent::__construct();

    }

     /**
     * 更新司机积分
     * @param string 
     * @param int 
     * @return int|boolean//成功时返回
     */
    public function updateDriverPoint($common_id,$service_rank){
        $driver_id = Db::name('order_common')->where('common_id',$common_id)->value('driver_id');
        $service_score = config('default_score')['service_score'];
        $old_score = Db::name('driver')->where('driver_id',$driver_id)->value('service_score');
        //查comment表中有多少条评论
        $sum = Db::name('comment')->where('driver_id',$driver_id)->sum('service_rank');
        $count = Db::name('comment')->where('driver_id',$driver_id)->count();
        $data['driver_point'] = $sum / $count;
        $data['service_score'] = $old_score+$service_score[$service_rank];
        return Db::name('driver')->where('driver_id',$driver_id)->update($data);
    }


}